from pydantic import Field
from pydantic_settings import BaseSettings, SettingsConfigDict
import os
from pathlib import Path


class Settings(BaseSettings):
    DASHSCOPE_API_KEY: str = Field(..., description="API key for ali services")
    ARK_API_KEY: str = Field(..., description="API key for doubao services")
    ZHIPUAI_API_KEY: str = Field(..., description="API key for zhipuai services")
    APP_PORT: int = Field(120, description="port for the application")
    APP_AUTO_RELOAD: bool = Field(
        False, description="whether to enable auto-reload for the application"
    )
    DEBUG: bool = Field(False, description="whether to enable debug mode")

    # env = Path(__file__).parent / ".env"
    # print(env)

    model_config = SettingsConfigDict(
        # env_file=os.getenv("ENV_FILE", ".env"),  # 优先用ENV_FILE，否则用.env,执行时的根目录
        env_file=os.getenv("ENV_FILE", Path(__file__).parent / ".env"),  # 文件所在目录
        env_file_encoding="utf-8",
        extra="ignore",
        # env_prefix="APP_"  # 环境变量前缀（如 APP_API_KEY）
    )


def get_settings() -> Settings:
    return Settings()


settings = get_settings()
